import freightTool from "./freightCalculateTool";
import markupTool from "./markupFreightTool.js";
export default {
	//参考运费
	referenceFreights(createForm, searchPriceData) {
		console.log("billing_model-----" + searchPriceData.billing_model);
		if (searchPriceData.billing_model == "1") {
			return this.referenceFreightExpress(createForm, searchPriceData);
		} else if (searchPriceData.billing_model == "2") {
			return this.referenceFreightLogistics(createForm, searchPriceData);
		} else if (searchPriceData.billing_model == "3") {
			return this.referenceFreightFixed(createForm, searchPriceData);
		} else {
			return this.getNullMoney();
		}
	},
	//运费 - 快运计算模式
	referenceFreightExpress(createForm, searchPriceData) {
		let weight = freightTool.getTotalWeight(createForm);
		let volume = freightTool.getTotalVolume(createForm);
		let zpb = freightTool.getZpb(createForm);
		let money = 0;
		//这版 有 重货 抛货 重抛货
		if (zpb >= 4) {
			//抛货
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(1, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceVolumeExpress(searchPriceData, volume);
		} else if (zpb > 2 && zpb < 4) {
			//重泡货
			// 1、重抛计算 2、重货计算 3、抛货计算 4、'0'
			if (freightTool.getWeightOrVolume(searchPriceData) == 1) {
				money = freightTool.referenceWeightVolumeExpress(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 2) {
				money = freightTool.referenceWeightExpress(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 3) {
				money = freightTool.referenceVolumeExpress(searchPriceData, weight, volume);
			} else {
				return this.getNullMoney();
			}
		} else if (zpb <= 2) {
			//重货
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(0, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceWeightExpress(searchPriceData, weight);
		}
		return this.getMarkupMoney(searchPriceData, money);
	},

	//运费 - 物流计算模式
	referenceFreightLogistics(createForm, searchPriceData) {
		let weight = freightTool.getTotalWeight(createForm);
		let volume = freightTool.getTotalVolume(createForm);
		let zpb = freightTool.getZpb(createForm);
		let money = 0;
		//这版 有 重货 抛货 重抛货
		if (zpb >= 4) {
			//抛货
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(1, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceVolumeLogistics(searchPriceData, volume);

		} else if (zpb > 2 && zpb < 4) {
			//重泡货
			// 1、重抛计算 2、重货计算 3、抛货计算 4、'0'
			if (freightTool.getWeightOrVolume(searchPriceData) == 1) {
				money = freightTool.referenceWeightVolumeLogistics(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 2) {
				money = freightTool.referenceWeightLogistics(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 3) {
				money = freightTool.referenceVolumeLogistics(searchPriceData, weight, volume);
			} else {
				return this.getNullMoney();
			}

		} else if (zpb <= 2) {
			//重货
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(0, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceWeightLogistics(searchPriceData, weight);
		}
		return this.getMarkupMoney(searchPriceData, money);
	},
	//运费 - 固定计算模式
	referenceFreightFixed(createForm, searchPriceData) {
		let weight = freightTool.getTotalWeight(createForm);
		let volume = freightTool.getTotalVolume(createForm);
		let zpb = freightTool.getZpb(createForm);
		let money = 0;
		//   'float_ratio':'', //下浮比例
		//这版 有 重货 抛货 重抛货
		if (zpb >= 4) {
			//抛货
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(1, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceVolumeFixed(searchPriceData, volume);
		} else if (zpb > 2 && zpb < 4) {
			//重泡货
			// 1、重抛计算 2、重货计算 3、抛货计算 4、'0'
			if (freightTool.getWeightOrVolume(searchPriceData) == 1) {
				money = freightTool.referenceWeightVolumeFixed(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 2) {
				money = freightTool.referenceWeightFixed(searchPriceData, weight, volume);
			} else if (freightTool.getWeightOrVolume(searchPriceData) == 3) {
				money = freightTool.referenceVolumeFixed(searchPriceData, weight, volume);
			} else {
				return this.getNullMoney();
			}
		} else if (zpb <= 2) {
			//重货 
			// 1抛货 0重货
			if (freightTool.getWeightOrVolumePrice(0, searchPriceData)) {
				return this.getNullMoney();
			}
			money = freightTool.referenceWeightFixed(searchPriceData, weight);
		}
		return this.getMarkupMoney(searchPriceData, money);
	},

	// 获取到的原始运费进一步计算 暂时无计算
	getMarkupMoney(searchPriceData, money) {
		return this.getShowMoney(money);
	},

	//无运费返回值
	getNullMoney() {
		return 0;
	},

	// 金额保留3位小数
	getShowMoney(money) {
		if (isNaN(money)) {
			return 0;
		} else {
			return parseFloat(money).toFixed(3);
		}
	},

	// 计算上浮后价格
	getMarkupShowMoney(searchPriceData, money) {
		var markupMoney = 0;
		if (searchPriceData.markup_type == 1) {
			markupMoney = markupTool.markupTypeBfb(searchPriceData, money);
		} else {
			markupMoney = markupTool.markupTypeMoney(searchPriceData, money);
		}
		return this.getShowMoney(markupMoney);
	},
	// 计算上浮的金额
	getSysMarkupMoney(markupMoney, money) {
		var markup_price = Number(markupMoney) - Number(money);
		return this.getShowMoney(markup_price);
	},

	getRefAllFreights(createForm, searchPriceData) {
		let money = this.referenceFreights(createForm, searchPriceData);
		let markupMoney = this.getMarkupShowMoney(searchPriceData, money);
		let markupPrice = this.getSysMarkupMoney(markupMoney, money);

		var data = {
			system_line_price: markupMoney,
			system_markup_price: markupPrice,
		}
		return data;
	},
};